using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace InduMall.Core.Models.Mapping
{
    public class AddressMap : EntityTypeConfiguration<Address>
    {
        public AddressMap()
        {
            // Primary Key
            this.HasKey(t => t.AddressId);

            // Properties
            this.Property(t => t.AddressDetail)
                .IsRequired()
                .HasMaxLength(64);

            this.Property(t => t.Phone)
                .IsRequired()
                .HasMaxLength(16);

            this.Property(t => t.Contactor)
                .IsRequired()
                .HasMaxLength(32);

            // Table & Column Mappings
            this.ToTable("Address");
            this.Property(t => t.AddressId).HasColumnName("AddressId");
            this.Property(t => t.UserId).HasColumnName("UserId");
            this.Property(t => t.StateId).HasColumnName("StateId");
            this.Property(t => t.CityId).HasColumnName("CityId");
            this.Property(t => t.DistrictId).HasColumnName("DistrictId");
            this.Property(t => t.AddressDetail).HasColumnName("AddressDetail");
            this.Property(t => t.Phone).HasColumnName("Phone");
            this.Property(t => t.Contactor).HasColumnName("Contactor");

            // Relationships
            this.HasRequired(t => t.User)
                .WithMany(t => t.Addresses)
                .HasForeignKey(d => d.UserId);

        }
    }
}
